﻿//-----------------------------------------------------------------------
// <copyright file="RetractMany.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the RetractMany class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.Archive.EngineOperation
{
    using System.Diagnostics;
    using Tuples;

    /// <summary>
    /// Represents an 'retract many' engine operation.   Retracts a collection of facts from the engine.
    /// </summary>
    internal class RetractMany : EngineOperation<object[]>
    {
        /// <summary>
        /// Initializes a new instance of the RetractMany class.
        /// </summary>
        /// <param name="session">The current tuple store session.</param>
        /// <param name="facts">A collection of facts to be retracted.</param>
        public RetractMany(TupleStoreSession session, object[] facts)
        {
            Debug.Assert(facts != null, "Fact array containing facts to be retracted cannot be null");

            this.session = session;
            this.data = facts;
        }

        #region IEngineOperation Members

        /// <summary>
        /// Performs the engine operation.
        /// </summary>
        /// <param name="facts">Ignored in this implementation.</param>
        /// <returns>Indicates if the engine should start a new match-resolve-do cycle.</returns>
        public override bool Perform(ref object[] facts)
        {
            // Retract the facts
            this.session.Retract(this.data);
            return false;
        }

        #endregion
    }
}
